/**
 * Copyright 2016-2018 mobaas.com
 */
package com.mobaas.devops.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mobaas.devops.PageList;
import com.mobaas.devops.dao.AccessLogDao;
import com.mobaas.devops.model.AccessLog;
import com.mobaas.devops.model.AccessTotal;
import com.mobaas.devops.service.AccessLogService;

/**
 * 
 * @author billy zhang
 * 
 */
@Service
public class AccessLogServiceImpl implements AccessLogService {

    @Autowired
    private AccessLogDao acclogMapper;

	@Override
	public void insertAccessLog(AccessLog acclog) {
		acclogMapper.insertAccessLog(acclog);
	}

	@Override
	public List<AccessTotal> selectAccessTotalListByApp(String appId, Date startDate, int interval) {

		return acclogMapper.selectAccessTotalListByApp(appId, startDate, interval);
	}

	@Override
	public PageList<AccessLog> selectAccessLogListByApp(String appId, int status, String path, 
			int pageNo, int pageSize) {

		PageList<AccessLog> plist = new PageList<>();
		plist.setPageNo(pageNo);
		plist.setPageSize(pageSize);
		plist.setTotal( acclogMapper.selectAccessLogCountByApp(appId, status, path) );
		if (plist.getTotal() > 0) {
			int offset = (pageNo - 1 ) * pageSize;
			plist.setList( acclogMapper.selectAccessLogListByApp(appId, status, path, offset, pageSize));
		}
		return plist;
	}
    
   
}
